package com.yuzhitong.shapi.base;

import com.yuzhitong.shapi.BuildConfig;
import com.yuzhitong.shapi.util.StringUtil;

import a.a.a.MyApplication;

import java.util.HashMap;

/**
 * MVP业务层基类
 * @param <V> View层
 */
public class BasePresenter<V extends BaseView> {
    protected V mView;


    /**
     * 绑定view，一般在初始化中调用该方法
     *
     * @param view view
     */
    public void attachView(V view) {
        this.mView = view;
    }

    /**
     * 解除绑定view，一般在onDestroy中调用
     */

    public void detachView() {
        this.mView = null;
    }

    /**
     * View是否绑定
     *
     * @return
     */
    public boolean isViewAttached() {
        return mView != null;
    }


    public HashMap<String, Object> getPublicPar() {
        HashMap<String, Object> par = new HashMap<>();
        if (!StringUtil.isEmpty(MyApplication.androidId)) {
            par.put("deviceId", MyApplication.androidId);
        }
        par.put("channel", BuildConfig.CHANNEL_VALUE);
        return par;
    }

    public boolean isProxy() {
        if (MyApplication.isIsProxy()) {
            mView.onError("网络错误");
            return true;
        }
        return false;
    }
}
